package com.zff.rental.repository.apartment;

import com.zff.rental.entity.apartment.RoomEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author HCY
 */
@Repository
public interface RoomRepository extends JpaRepository<RoomEntity, Long>, JpaSpecificationExecutor<RoomEntity> {
    /**
     * 根据公寓ID和房间名称是否存在
     *
     * @param apartmentId 公寓ID
     * @param name        房间名称
     * @return boolean
     */
    @Query("SELECT count(*) > 0 FROM RoomEntity WHERE apartmentId = :apartmentId AND name = :name")
    boolean existsByApartmentIdAndName(Long apartmentId, String name);

    List<RoomEntity> findAllByApartmentId(Long apartmentId);

    List<RoomEntity> findAllByApartmentIdInAndRentalStatus(List<Long> apartmentIdList, Byte rentalStatus);

    boolean existsByApartmentId(Long id);
}
